<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
</body>
<script>
function sum2(n) {
    var sum = 0;

    while (n > 0) {
        sum += n;
        n--;
    }

    return sum;
}

console.log( sum2(10) );        // 55
console.log( sum2(55555, 0) );  // 1543206790
</script>
</html>